package Algorthim;

import java.util.concurrent.locks.ReentrantReadWriteLock;

public class Splits {
	private int splits;
	private ReentrantReadWriteLock lock;
	
	public Splits(int size)
	{
		this.splits = size;
		this.lock = new ReentrantReadWriteLock();
	}
	
	public void setLimit(int newSize)
	{
		try
		{
			lock.writeLock().lock();
			this.splits = newSize;
		}
		finally
		{
			lock.writeLock().unlock();
		}
	}
	
	public int getLimit()
	{
		try
		{
			lock.readLock().lock();
			return this.splits;
		}
		finally
		{
			lock.readLock().unlock();
		}
	}
	
	public void incLimit()
	{
		try
		{
			lock.writeLock().lock();
			this.splits++;
		}
		finally
		{
			lock.writeLock().unlock();
		}
	}
	
	public void decLimit()
	{
		try
		{
			lock.writeLock().lock();
			this.splits--;
		}
		finally
		{
			lock.writeLock().unlock();
		}
	}
}
